<?php
class Webset extends Admin_Controller
{

	function __construct()
	{
		parent::__construct();
		$this->load->library('form_validation');
	}

	public function delcaches()
	{	
		$data['title'] = 'Settings';
		$data['siderbar'] = 'webset/delcaches';
		$data['submenu'] = 'webset/delcaches';
		$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
		$this->cache->clean();
		show_message('清除站内缓存成功',site_url(X_URL.'home'),1);
	}	
	
	public function allset()
	{
		if($_POST){
			$config['site_name'] = $this->input->post('site_name');
			$config['site_domain'] = $this->input->post('site_domain');
			$config['site_short_name'] = $this->input->post('site_short_name');
			$config['site_keywords'] = $this->input->post('site_keywords');
			$config['site_description'] = $this->input->post('site_description');
			$config['sub_folder'] = $this->input->post('sub_folder');
			$config['encryption_key'] = $this->input->post('encryption_key');
			$config['is_rewrite'] = $this->input->post('is_rewrite');
			$config['voucher_close'] = $this->input->post('voucher_close');
			$config['site_beian'] = $this->input->post('site_beian');
			$config['site_infos'] = $this->input->post('site_infos');
			$config['site_tel'] = $this->input->post('site_tel');
			$config['site_app'] = $this->input->post('site_app');
			$config['site_android'] = $this->input->post('site_android');
			$config['app_updateinfo'] = $this->input->post('app_updateinfo');
			$config['app_downloadurl'] = $this->input->post('app_downloadurl');
			$config['is_must'] = $this->input->post('is_must');
			if($this->input->post('is_rewrite')=='on'){
				$config['index_page']='';
			} else {
				$config['index_page']='index.php';
			}
			$this->config->set_item('webset', $config);
			$this->config->save('webset',$config);

			show_message('网站配置更新成功',site_url(X_URL.'webset/allset'),1);
		}
		
		$this->load->view('webset/allset');
	}

	public function loglist($page=1)
	{
		/** 检查登陆 */
		if($this->auth->is_admin())
		{
			$data['title'] = '登陆日志';
			$data['siderbar'] = 'webset/allset';
			$data['submenu'] = 'webset/allset';
			$data['total'] = $this->log_m->count_log();
			//分页
			$limit = 20;
			$config['uri_segment'] = 4;
			$config['use_page_numbers'] = TRUE;
			$config['base_url'] = base_url(X_URL.'webset/loglist');
			$config['total_rows'] = $data['total'];
			$config['per_page'] = $limit;
			$config['prev_link'] = '&larr;';
			$config['prev_tag_open'] = '<li class=\'prev\'>';
			$config['prev_tag_close'] = '</li';
			$config['cur_tag_open'] = '<li class=\'active\'><span>';
			$config['cur_tag_close'] = '</span></li>';
			$config['num_tag_open'] = '<li>';
			$config['num_tag_close'] = '</li>';
			$config['next_link'] = '&rarr;';
			$config['next_tag_open'] = '<li class=\'next\'>';
			$config['next_tag_close'] = '</li>';
			$config['first_link'] = 'First Page';
			$config['first_tag_open'] = '<li class=\'first\'>';
			$config['first_tag_close'] = '</li>';
			$config['last_link'] = 'Last Page';
			$config['last_tag_open'] = '<li class=\'last\'>';
			$config['last_tag_close'] = '</li>';
			$config['num_links'] = 5;
			
			$this->load->library('pagination');
			$this->pagination->initialize($config);
			
			$start = ($page-1)*$limit;
			$data['pagination'] = $this->pagination->create_links();

			$data['info_list'] = $this->log_m->log_list($start, $limit);
			$this->load->view('logs_list', $data);
		}else{
			show_message('您没有此管理权限',site_url('user/login'));
		}
	}
	
	public function dellog($id)
	{
		/** 检查登陆 */
		if($this->auth->is_admin())
		{
			$data['title'] = '删除日志';
			$data['siderbar'] = 'webset/allset';
			$data['submenu'] = 'webset/allset';
			//删除
			if($this->log_m->del_log($id)){
				show_message('删除日志成功',site_url(X_URL.'webset/loglist'),1);
			}				

		}else{
			show_message('您没有此管理权限',site_url('user/login'));
		}
	}
	
	public function dellog_all()
	{
		/** 检查登陆 */
		if($this->auth->is_admin())
		{
			$data['title'] = '删除日志';
			$data['siderbar'] = 'webset/allset';
			$data['submenu'] = 'webset/allset';
			//删除
			$this->log_m->del_all();
			show_message('清空日志成功',site_url(X_URL.'webset/loglist'),1);

		}else{
			show_message('您没有此管理权限',site_url('user/login'));
		}
	}


}